package com.shelpe.services.sinbad.controller.actionLog;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.shelpe.services.sinbad.entity.jpa.Adgroup;
import com.shelpe.services.sinbad.entity.jpa.AdgroupLog;
import com.shelpe.services.sinbad.entity.jpa.AreaList;
import com.shelpe.services.sinbad.entity.jpa.Campaign;
import com.shelpe.services.sinbad.entity.jpa.CampaignLog;
import com.shelpe.services.sinbad.entity.jpa.CreativeLog;
import com.shelpe.services.sinbad.entity.jpa.KeywordsLog;

public class ActionLogService implements ActionLogConverter {
	@Autowired
	private ObjectMapper objectMapper;

	@Override
	public ActionLogDto convertKeywrod(KeywordsLog entity, Map<Long, Campaign> campaignMap,
			Map<Long, Adgroup> adgroupMap) {
		return null;
	}

	@Override
	public ActionLogDto convertCreative(CreativeLog entity, Map<Long, Campaign> campaignMap,
			Map<Long, Adgroup> adgroupMap) {
		return null;
	}

	@Override
	public ActionLogDto convertCampaign(CampaignLog entity, Map<Long, Campaign> campaignMap, List<AreaList> areas) {
		return null;
	}

	@Override
	public ActionLogDto convertAdgroup(AdgroupLog entity, Map<Long, Campaign> campaignMap,
			Map<Long, Adgroup> adgroupMap) {
		return null;
	}

	public AdgroupVo unserialize(String diff) { // 反序列化，字符串到对象的过程
		try {
			return objectMapper.readerFor(AdgroupVo.class).readValue(diff);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public CreativeVo unserializeCreative(String diff) { // 反序列化，字符串到对象的过程
		try {
			return objectMapper.readerFor(CreativeVo.class).readValue(diff);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public KeywordVo unserializeKeyword(String diff) { // 反序列化，字符串到对象的过程
		try {
			return objectMapper.readerFor(KeywordVo.class).readValue(diff);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public CampaignVo unserializeCampaign(String diff) { // 反序列化，字符串到对象的过程
		try {
			return objectMapper.readerFor(CampaignVo.class).readValue(diff);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String area(List<Integer> areas) {
		Map<Integer, String> map = new HashMap<Integer, String>();
		map.put(1, "安徽");
		map.put(19, "北京");
		map.put(39, "福建");
		map.put(52, "甘肃");
		map.put(68, "广东");
		map.put(92, "广西");
		map.put(109, "贵州");
		map.put(120, "海南");
		map.put(125, "河北");
		map.put(145, "河南");
		map.put(165, "黑龙江");
		map.put(184, "湖北");
		map.put(212, "湖南");
		map.put(234, "吉林");
		map.put(255, "江苏");
		map.put(279, "江西");
		map.put(294, "辽宁");
		map.put(333, "内蒙古");
		map.put(351, "宁夏");
		map.put(357, "青海");
		map.put(368, "山东");
		map.put(393, "山西");
		map.put(406, "陕西");
		map.put(417, "上海");
		map.put(438, "四川");
		map.put(461, "天津");
		map.put(488, "云南");
		map.put(508, "浙江");
		map.put(532, "重庆");
		map.put(471, "新疆");
		map.put(463, "西藏");
		map.put(577, "台湾");
		map.put(576, "澳门");
		map.put(599, "香港");
		map.put(531, "中国其它");
		map.put(574, "国外");
		map.put(9999, "中国大陆");

		StringBuffer buff = new StringBuffer();
		for (int area : areas) {
			buff.append(map.get(area));
			buff.append(",");
		}

		return buff.substring(0, buff.lastIndexOf(","));
	}

}
